package com.example.demo.design.demo15_abstractFactory;

import com.fasterxml.classmate.util.ClassKey;

/**
 * Created by 蔡超 on 2018/10/4.
 */
public class DataAccess {
    public static final String COMPANY_HP = "HP";
    public static final String COMPANY_DELL = "DELL";

    public static Mouse createMouse(String type){
        Mouse mouse = null;
        switch (type){
            case COMPANY_HP:
                Factory factory = new HPFactory();
                mouse = factory.createMouse();
                break;
            case COMPANY_DELL:
                Factory factory2 = new DellFactory();
                mouse = factory2.createMouse();
                break;
        }
        return mouse;
    }

    public static Keyboard createKeyBoard(String type){
        Keyboard keyboard = null;
        switch (type){
            case COMPANY_HP:
                Factory factory = new HPFactory();
                keyboard = factory.createKeyboard();
                break;
            case COMPANY_DELL:
                Factory factory2 = new DellFactory();
                keyboard = factory2.createKeyboard();
                break;
        }
        return keyboard;
    }

    public static Mouse createMouseByReflex(String type) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        String className = "com.example.demo.design.demo15_abstractFactory." + type + "Mouse";
        Class<Mouse> mouseClass = (Class<Mouse>) Class.forName(className);
        return mouseClass.newInstance();
    }

    public static Keyboard createKeyboard(String type) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        String className = "com.example.demo.design.demo15_abstractFactory." + type + "Keyboard";
        Class<Keyboard> keyboardClass = (Class<Keyboard>) Class.forName(className);
        return keyboardClass.newInstance();
    }

}
